home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 1.toast / pc / sample code / contributed / waste / waste 1.3 / source / weselectors.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.8 KB  |  204 lines

  1. /*
  2.  *    WESelectors.c
  3.  *
  4.  *    WASTE PROJECT
  5.  *  Routines for manipulating selector lookup tables
  6.  *
  7.  *  Copyright (c) 1993-1998 Marco Piovanelli
  8.  *    All Rights Reserved
  9.  *
  10.  *  C port by Dan Crevier
  11.  *
  12.  */
  13.  
  14.  
  15. #include "WASTEIntf.h"
  16.  
  17. // MPW can't handle FIELD_DESC stuff (duh!)
  18.  
  19. #ifdef applec
  20.  
  21. //#error "hand-made selector tables not up-to-date!"
  22.  
  23. // this is **ugly** and will break if we change the declaration of WERec
  24.  
  25. WELookupTable _weMainSelectorTable[] = {
  26. { weRefCon,                     0x0078, 0x0004 },
  27. { wePort,                        0x0000, 0x0004 },
  28. { weText,                        0x0004, 0x0004 },
  29. { weCharToPixelHook,            0x00C0, 0x0004 },
  30. { weCharByteHook,                0x00CC, 0x0004 },
  31. { weCharTypeHook,                0x00D0, 0x0004 },
  32. { weClickLoop,                    0x009C, 0x0004 },
  33. { weDrawTextHook,                0x00B8, 0x0004 },
  34. { weEraseHook,                    0x00D4, 0x0004 },
  35. { weFluxProc,                    0x00D8, 0x0004 },
  36. { weLineBreakHook,                0x00C4, 0x0004 },
  37. { weLineArray,                    0x0008, 0x0004 },
  38. { wePixelToCharHook,            0x00BC, 0x0004 },
  39. { weRunArray,                    0x0010, 0x0004 },
  40. { weScrollProc,                    0x00A0, 0x0004 },
  41. { weStyleTable,                    0x000C, 0x0004 },
  42. { weWordBreakHook,                0x00C8, 0x0004 },
  43.  
  44. #if WASTE_TSM_SUPPORT
  45. { weTSMPostUpdate,                0x00A8, 0x0004 },
  46. { weTSMPreUpdate,                0x00A4, 0x0004 },
  47. { weTSMDocumentID,                0x0080, 0x0004 },
  48. #endif
  49.  
  50. #if WASTE_DRAG_AND_DROP
  51. { weCurrentDrag,                0x008C, 0x0004 },
  52. { wePreTrackDragHook,            0x00AC, 0x0004 },
  53. { weHiliteDropAreaHook,         0x00B4, 0x0004 },
  54. { weTranslateDragHook,            0x00B0, 0x0004 },
  55. #endif
  56.  
  57. #if WASTE_TRANSLUCENT_DRAGS
  58. { weTranslucencyThreshold,        0x00F4, 0x0004 },
  59. #endif
  60.  
  61. #if WASTE_IC_SUPPORT
  62. { weURLHint,                    0x00F8, 0x0004 },
  63. #endif
  64.  
  65. { 0,                     0, 0 }};
  66.  
  67. #if WASTE_OBJECTS
  68.  
  69. WELookupTable _weObjectHandlerSelectorTable[] = {
  70. { weClickHandler,        0x0010, 0x0004 },
  71. { weDrawHandler,        0x000C, 0x0004 },
  72. { weDisposeHandler,        0x0008, 0x0004 },
  73. { weNewHandler,            0x0004, 0x0004 },
  74. { weStreamHandler,      0x0014, 0x0004 },
  75. { weRefCon,             0x0018, 0x0004 },
  76. { 0,                     0, 0 }};
  77.  
  78. #endif  // WASTE_OBJECTS
  79.  
  80. #else
  81.  
  82. // proper way of defining selector tables
  83.  
  84. #define FIELD_OFFSET(FIELD, STRUCT)        (int) &((STRUCT *) 0L)->FIELD
  85. #define FIELD_SIZE(FIELD, STRUCT)        sizeof(((STRUCT *) 0L)->FIELD)
  86. #define FIELD_DESC(FIELD, STRUCT)        { FIELD_OFFSET(FIELD, STRUCT), FIELD_SIZE(FIELD, STRUCT) }
  87.  
  88. WELookupTable _weMainSelectorTable[] = {
  89. { weRefCon,                 FIELD_DESC(refCon,                    WERec) },
  90. { wePort,                    FIELD_DESC(port,                      WERec) },
  91. { weText,                    FIELD_DESC(hText,                     WERec) },
  92. { weCharToPixelHook,        FIELD_DESC(charToPixelHook,           WERec) },
  93. { weCharByteHook,            FIELD_DESC(charByteHook,              WERec) },
  94. { weCharTypeHook,            FIELD_DESC(charTypeHook,              WERec) },
  95. { weClickLoop,                FIELD_DESC(clickLoop,                 WERec) },
  96. { weDrawTextHook,            FIELD_DESC(drawTextHook,              WERec) },
  97. { weEraseHook,                FIELD_DESC(eraseHook,                WERec) },
  98. { weFluxProc,                FIELD_DESC(fluxProc,                WERec) },
  99. { weLineBreakHook,            FIELD_DESC(lineBreakHook,             WERec) },
  100. { weLineArray,                FIELD_DESC(hLines,                    WERec) },
  101. { wePixelToCharHook,        FIELD_DESC(pixelToCharHook,           WERec) },
  102. { weRunArray,                FIELD_DESC(hRuns,                     WERec) },
  103. { weScrollProc,                FIELD_DESC(scrollProc,                WERec) },
  104. { weStyleTable,                FIELD_DESC(hStyles,                   WERec) },
  105. { weWordBreakHook,            FIELD_DESC(wordBreakHook,            WERec) },
  106.  
  107. #if WASTE_TSM_SUPPORT
  108. { weTSMPostUpdate,            FIELD_DESC(tsmPostUpdate,             WERec) },
  109. { weTSMPreUpdate,            FIELD_DESC(tsmPreUpdate,              WERec) },
  110. { weTSMDocumentID,            FIELD_DESC(tsmReference,              WERec) },
  111. #endif
  112.  
  113. #if WASTE_DRAG_AND_DROP
  114. { weCurrentDrag,            FIELD_DESC(currentDrag,               WERec) },
  115. { wePreTrackDragHook,        FIELD_DESC(preTrackDragHook,        WERec) },
  116. { weHiliteDropAreaHook,        FIELD_DESC(hiliteDropAreaHook,        WERec) },
  117. { weTranslateDragHook,        FIELD_DESC(translateDragHook,         WERec) },
  118. #endif
  119.  
  120. #if WASTE_TRANSLUCENT_DRAGS
  121. { weTranslucencyThreshold,     FIELD_DESC(translucencyThreshold,    WERec) },
  122. #endif
  123.  
  124. #if WASTE_IC_SUPPORT
  125. { weURLHint,                FIELD_DESC(hURLHint,                  WERec) },
  126. #endif
  127.  
  128. { 0,                     0, 0 }};
  129.  
  130. #if WASTE_OBJECTS
  131.  
  132. WELookupTable _weObjectHandlerSelectorTable[] = {
  133. { weClickHandler,        FIELD_DESC(clickHandler,      WEOHTableEntry) },
  134. { weDrawHandler,        FIELD_DESC(drawHandler,       WEOHTableEntry) },
  135. { weDisposeHandler,        FIELD_DESC(freeHandler,       WEOHTableEntry) },
  136. { weNewHandler,            FIELD_DESC(newHandler,        WEOHTableEntry) },
  137. { weStreamHandler,      FIELD_DESC(streamHandler,     WEOHTableEntry) },
  138. { weRefCon,             FIELD_DESC(refCon,            WEOHTableEntry) },
  139. { 0,                     0, 0 }};
  140.  
  141. #endif    // WASTE_OBJECTS
  142.  
  143. #endif    // !applec
  144.  
  145. pascal void _WELookupSelector(const WELookupTable *table, WESelector selector, WEFieldDescriptor *desc)
  146. {
  147.     for ( ; table->selector != selector ; table++ )
  148.     {
  149.         if ( * (SInt32 *) &(table->desc) == 0L )
  150.         {
  151.             break;
  152.         }
  153.     }
  154.  
  155.     *desc = table->desc;
  156. }
  157.  
  158. pascal OSErr _WEGetField(const WELookupTable *table, WESelector selector, SInt32 *info, void *structure)
  159. {
  160.     WEFieldDescriptor desc;
  161.  
  162.     _WELookupSelector(table, selector, &desc);
  163.  
  164.     if (desc.fLength == 0)
  165.     {
  166.         return weUndefinedSelectorErr;
  167.     }
  168.  
  169.     *info = * (SInt32 *) ((SInt32) structure + desc.fOffset);
  170.     return noErr;
  171. }
  172.  
  173. pascal OSErr _WESetField(const WELookupTable *table, WESelector selector, SInt32 *info, void *structure)
  174. {
  175.     WEFieldDescriptor desc;
  176.  
  177.     _WELookupSelector(table, selector, &desc);
  178.  
  179.     if (desc.fLength == 0)
  180.     {
  181.         return weUndefinedSelectorErr;
  182.     }
  183.  
  184.     * (SInt32 *) ((SInt32) structure + desc.fOffset) = *info;
  185.     return noErr;
  186. }
  187.  
  188. pascal OSErr WEGetInfo(WESelector selector, void *info, WEHandle hWE)
  189. {
  190.     return _WEGetField(_weMainSelectorTable, selector, (SInt32 *) info, *hWE);
  191. }
  192.  
  193. pascal OSErr WESetInfo(WESelector selector, const void *info, WEHandle hWE)
  194. {
  195.     OSErr err;
  196.  
  197.     err = _WESetField(_weMainSelectorTable, selector, (SInt32 *) info, *hWE);
  198.  
  199.     // the hook fields can never be nil, so replace any nil field with the default address
  200.     _WESetStandardHooks(hWE);
  201.  
  202.     return err;
  203. }
  204.